﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SolrExample.Common.Helpers
{
    public static class CommonHelper
    {
        public static IList<IList<T>> PageDataList<T>(IList<T> dataList, int batchSize)
        {
            IList<IList<T>> result = new List<IList<T>>();

            if (batchSize <= 0 || dataList.Count == 0 || dataList.Count <= batchSize)
            {
                result.Add(dataList);
                return result;
            }

            int groupCount = (int)Math.Ceiling((decimal)dataList.Count / batchSize);
            for (int i = 0; i < groupCount; i++)
            {
                int startIndex = i * batchSize;

                result.Add(dataList.Skip(startIndex).Take(batchSize).ToList());
            }

            return result;
        }
    }
}
